<template>
  <div class="mod-config">
    <div>
      <el-button type="primary" @click="showInfo()" style="margin-bottom: 20px;">新增</el-button>
    </div>
    <el-table :data="dataList" border v-loading="dataListLoading" style="width: 100%;">
      <el-table-column prop="id" header-align="center" align="center" label="ID"></el-table-column>
      <el-table-column prop="version" header-align="center" align="center" label="版本名"></el-table-column>
      <el-table-column prop="versionCode" header-align="center" align="center" label="版本号"></el-table-column>
      <el-table-column prop="jumpUrl" header-align="center" align="center" label="跳转地址 "></el-table-column>
      <el-table-column prop="isAudit" header-align="center" align="center" label="是否强制更新">
        <template slot-scope="scope">
          {{ scope.row.forcedUpdate === 1 ? '是' : '否' }}
        </template>
      </el-table-column>
      <el-table-column prop="isExpire" header-align="center" align="center" label="系统类型">
        <template slot-scope="scope">
          {{ scope.row.systemType === 1 ? '安卓' : 'ios' }}
        </template>
      </el-table-column>
      <el-table-column header-align="center" align="center" width="120" label="操作">
        <template slot-scope="scope">
          <el-button type="text" size="small" @click="showInfo(scope.row.id)">修改</el-button>
          <!--<el-button type="text" size="small" @click="del(scope.row.id)">删除</el-button>-->
        </template>
      </el-table-column>
    </el-table>
    <el-pagination
      @size-change="sizeChangeHandle"
      @current-change="currentChangeHandle"
      :current-page="pageIndex"
      :page-sizes="[10, 20, 50, 100]"
      :page-size="pageSize"
      :total="totalPage"
      layout="total, sizes, prev, pager, next, jumper"
    ></el-pagination>
    <audits-manage-add ref="auditsManageAdd" @refresh = 'getDataList'></audits-manage-add>
  </div>
</template>

<script>
  import AuditsManageAdd from "./configManageAdd";
  export default {
    data() {
      return {
        dataList: [],
        dataListLoading: false,
        dataForm: {},
        pageIndex: 1,
        pageSize: 10,
        totalPage: 0,
      };
    },
    components: {
      AuditsManageAdd
    },
    mounted() {
    },
    activated() {
      this.getDataList();
    },
    methods: {
      // 获取数据列表
      getDataList() {
        this.dataListLoading = true;
        let obj = {
          page: this.pageIndex,
          limit: this.pageSize,
        };
        this.$http({
          url: this.$http.adornUrl("/common/appnewestversion/list"),
          method: "get",
          params: this.$http.adornParams(obj)
        }).then(({ data }) => {
          if (data && data.code === 0) {
            this.dataList = data.page.list;
            this.totalPage = data.page.totalCount;
          } else {
            this.dataList = [];
            this.totalPage = 0;
          }
          this.dataListLoading = false;
        });
      },
      showInfo(id) {
        this.$nextTick(() => {
          this.$refs.auditsManageAdd.initData(id);
        })
      },
      del(id) {
        this.$http({
          url: this.$http.adornUrl("/common/appversion/delete"),
          method: "post",
          params: this.$http.adornParams({ids: id})
        }).then(({ data }) => {
          if (data && data.code === 0) {
            console.log('删除成功')
          } else {
            console.log('删除失败')
          }
        });
      },
      // 每页数
      sizeChangeHandle(val) {
        this.pageSize = val;
        this.pageIndex = 1;
        this.getDataList();
      },
      // 当前页
      currentChangeHandle(val) {
        this.pageIndex = val;
        this.getDataList();
      },
    }
  };
</script>
